package com.lh.recallbootrabbitmq.manage;

import com.lh.recallbootrabbitmq.bean.Result;
import com.lh.recallbootrabbitmq.constants.ResultEnum;
import com.lh.recallbootrabbitmq.exception.RabbitMQExceptionUtils;
import com.lh.recallbootrabbitmq.util.ValidateUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.rabbit.core.RabbitAdmin;
import org.springframework.beans.factory.annotation.Autowired;


/**
 * @author lh
 * @Description: 交换机、队列管理基类
 * @date 2021/8/17 14:56
 */
public abstract class AbstractManage {
	private static final Logger logger = LoggerFactory.getLogger(AbstractManage.class);
	@Autowired
	RabbitAdmin rabbitAdmin;

	/**
	 * 自定义的校验
	 *
	 * @param object
	 */
	public abstract void DefinedValidate(Object object);

	/**
	 * 通用校验
	 * 1. 校验字段是否是非空
	 *
	 * @param object
	 */
	public void validate(Object object) {
		Result result = ValidateUtils.validate(object);
		if (!ResultEnum.success().equals(result.getCode())) {
			RabbitMQExceptionUtils.throwRabbitMQException(result.getMsg());
		}

		this.DefinedValidate(object);
	}

}
